﻿using System;
using System.Collections.Generic;
using System.Text;
using Lswweb.Model;
using System.Web.UI.WebControls;
using Lswweb.Domain;

namespace Lswweb.Controls
{
    public class ProductShow : SkinnedWebControl
    {
        private Label lbCategoryName;
        private Label lbIspop;
        private Label lbIstop;
        private Label lbDatecreated;
        private Label lbTitle;
        private Label lbKeys;
        private Label lbSummary;
        private Label lbContent;
        private Label lbContent2;
        private Label lbContent3;
        private Label lbContent4;
        private Label lbModel;
        private Label lbAuditingStatus;
        private Label lbPath;
        private Image img;

        protected override void InitializeSkin(System.Web.UI.Control skin)
        {
            lbCategoryName = (Label)skin.FindControl("lbCategoryName");
            lbIspop = (Label)skin.FindControl("lbIspop");
            lbIstop = (Label)skin.FindControl("lbIstop");
            lbDatecreated = (Label)skin.FindControl("lbDatecreated");
            lbTitle = (Label)skin.FindControl("lbTitle");
            lbKeys = (Label)skin.FindControl("lbKeys");
            lbSummary = (Label)skin.FindControl("lbSummary");
            lbContent = (Label)skin.FindControl("lbContent");
            lbContent2 = (Label)skin.FindControl("lbContent2");
            lbContent3 = (Label)skin.FindControl("lbContent3");
            lbContent4 = (Label)skin.FindControl("lbContent4");
            lbModel = (Label)skin.FindControl("lbModel");
            lbAuditingStatus = (Label)skin.FindControl("lbAuditingStatus");
            lbPath = (Label)skin.FindControl("lbPath");
            img = (Image)skin.FindControl("img");

            if (Info != null)
            {
                Page.Title = Info.Title;
                Page.Description = Info.Summary;
                Page.Keywords = Info.Keys;

                if ( lbCategoryName!= null)
                    lbCategoryName.Text = TreeTables.ProductCategories.GetCategoryName(Info.ProductCategoryId);

                if (lbIspop != null)
                    lbIspop.Text = Info.IsHot.ToString();

                if (lbIstop != null)
                    lbIstop.Text = Info.IsTop.ToString();

                if (lbDatecreated != null)
                    lbDatecreated.Text = Info.DateCreated.ToString(SiteSettings.Settings.DateTimeFormat);

                if ( lbTitle!= null)
                    lbTitle.Text = Info.Title;

                if ( lbKeys!= null)
                    lbKeys.Text = Info.Keys;

                if ( lbSummary!= null)
                    lbSummary.Text = Info.Summary;

                if ( lbContent!= null)
                    lbContent.Text = Info.Content;

                if (lbContent2 != null)
                    lbContent2.Text = Info.Content2;

                if (lbContent3 != null)
                    lbContent3.Text = Info.Content3;

                if (lbContent4 != null)
                    lbContent4.Text = Info.Content4;

                if ( lbAuditingStatus!= null)
                    lbAuditingStatus.Text = Enum<AuditingStatusType>.GetEnumStr(Info.AuditingStatus);

                if (lbPath != null)
                    lbPath.Text = TreeTables.ProductCategories.GetPathText(Info.ProductCategoryId);

                if (img != null)
                {
                    img.ImageUrl = Info.ImageUrl;

                    if (string.IsNullOrEmpty(img.ImageUrl))
                        img.Visible = false;
                }

                if (lbModel != null)
                    lbModel.Text = Info.ProductCode;
            }
        }

        private ProductInfo _info;
        public ProductInfo Info
        {
            get
            {
                if (_info == null)
                    _info = Products.GetProduct(ProductId);
                return _info;
            }
        }

        private int _id = -1;
        public int ProductId
        {
            get 
            {
                if (_id == -1 && SiteContext.Current.Id > 0)
                    _id = SiteContext.Current.Id;

                return _id;
            }
            set { _id = value; }
        }

        protected override string DefaultSkinFilename
        {
            get { return "ProductShow.ascx"; }
        }
    }
}
